class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
    
    def toList(self):
        head = self
        res = [head.val]
        while head.next:
            head = head.next
            res.append(head.val)
        return res
    
    def __repr__(self):
        return self.toList().__repr__()
    
def NodesFromList(l):
    if l:
        head = ListNode(l[0])
        p = head
        for i in l[1:]:
            p.next = ListNode(i)
            p = p.next
        return head

if __name__ == '__main__':
    h = NodesFromList([1,2,3])
    print(h.toList())
    print(h)